package com.cwh.controller;


import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cwh.exception.EmployeeException;

@Controller
public class LoginController{
	
	
	@RequestMapping("/login")
	public String test( HttpServletRequest request,Model m) throws Exception{
		String exceptionName =(String) request.getAttribute("shiroLoginFailure");
		
		//有异常
		if(exceptionName!=null) {
			if(UnknownAccountException.class.getName().equals(exceptionName)) {
//				throw new EmployeeException("用户名错误！！！");
				System.out.println("用户名错误！！！");
				m.addAttribute("errorMsg", "用户名错误！！！");
			}else if(IncorrectCredentialsException.class.getName().equals(exceptionName)){
//				throw new EmployeeException("密码错误");
				System.out.println("密码错误");
				m.addAttribute("errorMsg", "密码错误");
			}else {
				System.out.println("其他错误");
//				throw new Exception();
				m.addAttribute("errorMsg", "其他错误");
			}
		}
		//无异常 跳转login视图
		return "login";
	}

}
